<template>
  <div class="huanxing-search">
    <el-autocomplete
      v-model="state"
      :fetch-suggestions="querySearch"
      popper-class="my-autocomplete"
      placeholder="请输入您要查找的菜单"
      style="width:380px"
      @select="handleSelect"
    >
      <template #default="{ item }">
        <div class="value">{{ item.label }}</div>
        <span class="link">{{ item.path }}</span>
      </template>
    </el-autocomplete>
    <el-button type="primary">搜索</el-button>
  </div>
</template>
<script>
import { defineComponent, ref, onMounted, computed } from 'vue'
import { useStore } from 'vuex'
export default defineComponent({
  name: 'topSearch',
  setup() {
    const store = useStore()
    //查询菜单
    const menu = computed(() => store.getters.menu)
    const state = ref('')

    const querySearch = (queryString, cb) => {
      const results = queryString
        ? menu.value.filter(createFilter(queryString))
        : menu.value
      // call callback function to return suggestion objects
      cb(results)
    }
    const createFilter = (queryString) => {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        )
      }
    }
    const handleSelect = (item) => {}

    onMounted(() => {})
    return {
      state,
      querySearch,
      handleSelect,
    }
  },
})
</script>
<style lang="scss" scoped>
.huanxing-search {
  margin-top: 10%;
  position: fixed;
  z-index: 2000;
  top: 0;
  right: 0;
  left: calc(50% - 200px);
  width: 400px;
  display: flex;
  align-items: center;
}
.my-autocomplete li {
  line-height: normal;
  padding: 7px;
}
.my-autocomplete li .name {
  text-overflow: ellipsis;
  overflow: hidden;
}
.my-autocomplete li .addr {
  font-size: 12px;
  color: #b4b4b4;
}
.my-autocomplete li .highlighted .addr {
  color: #ddd;
}
</style>